package com.ibm.mall.app.action;

import java.util.HashMap;
import java.util.Map;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ibm.mall.base.BaseAction;
import com.ibm.mall.model.User;
import com.ibm.mall.util.MD5Util;
import com.opensymphony.xwork2.ActionContext;

@Controller
@Scope("prototype")
public class LoginAction extends BaseAction<User> {

	private static final long serialVersionUID = 1L;
	
	private Map responseJson=new HashMap();
	
	private String account;
	
	private String password;
	
    public Map getResponseJson() {   
        return responseJson;   
    }
    
    public void setResponseJson(Map responseJson) {   
        this.responseJson = responseJson;   
    }
	
	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String login() {
		String msg="";
		User u=userService.getUserByUserAccount(account);
		if(u==null){
			msg="用户名不存在";
		}else{
			if(u.getUserPassword().equals(MD5Util.MD5(password))){
				ActionContext.getContext().getSession().put("app_user", u);
				responseJson.put("user", u);
				msg="登录成功";
			}else{
				msg="密码不正确";
			}
		}
		responseJson.put("msg", msg);
		return "login";
	}

}
